/*
 * User: rant
 * Date: Aug 13, 2007
 *
 *
 */
package laMalinche.propertyChangeAdapters.rules;


import laMalinche.constraint.BasicConstraintResultHolder;
import laMalinche.constraint.ConstraintManager;
import laMalinche.constraint.ConstraintResult;
import laMalinche.rete.rule.*;
import laMalinche.DevMode;

import java.util.*;

import com.google.inject.Inject;

/**
 *
 */
public class BasicConstraintRule extends BasicProductionRule implements Action {
	private ActionType actionType = ActionType.other;
	private final List<Condition> conditions = new ArrayList<Condition>();
	private String name;

    @Inject
    ConstraintManager constraintManager;
    

    public BasicConstraintRule(String name) {
        DevMode.getInstance().getInjector().injectMembers(this);
        initialize(name);
	}

	private void initialize(String name) {
		this.name = name;
		setProductionRuleType(BusinessRuleType.constraint);
		setAction(this);
	}

	public BasicConstraintRule(String name,final ActionType actionType) {
		this.actionType = actionType;
		initialize(name);
	}

	public void addCondition(Condition condition){
			conditions.add(condition);
	}

	public List<Condition> getConditions() {
		return conditions;
	}

	public ActionType getActionType() {
		return actionType;
	}

	public void execute() {
		final BasicConstraintResultHolder resultHolder = (BasicConstraintResultHolder) constraintManager.getConstraintResultHolder();
		final ConstraintResult constraintResult = resultHolder.getConstraintResult();
		constraintResult.addConstraint(this);
	}

	@Override
    public String getName() {
		return name;
	}
}